package com.brzjomo.embraceofthevoid.items;

import net.minecraft.block.entity.BlockEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;

import java.util.Objects;

public class NBTStick extends Item {
    public NBTStick(Settings settings) {
        super(settings);
    }

    @Override
    public ActionResult useOnBlock(ItemUsageContext context) {
        BlockEntity blockEntity = context.getWorld().getBlockEntity(context.getBlockPos());

        if (blockEntity != null) {
            NbtCompound nbt = Objects.requireNonNull(blockEntity).createNbtWithIdentifyingData();
            String message = nbt.toString();
            Objects.requireNonNull(context.getPlayer()).sendMessage(Text.of(message), false);
        } else {
            Objects.requireNonNull(context.getPlayer()).sendMessage(Text.translatable("commands.data.block.invalid"), false);
        }
        return super.useOnBlock(context);
    }
}
